Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto detect background image #7849

Merged
22 commits merged into from
Oct 15, 2020

Conversation

bennettnicholas
Copy link
Contributor

@bennettnicholas bennettnicholas commented Oct 7, 2020

Summary of the Pull Request

Added watch on desktopImagePath to check when the path equals "DesktopWallpaper"
If it does equal "DesktopWallpaper" it replaces the path with a path to the desktop's wallpaper

*I am a student and this is my first pull request for Terminal so please give feedback no matter how small. It's the best way I can learn.

PR Checklist

Detailed Description of the Pull Request / Additional comments

I am using SystemParametersInfo for SPI_GETDESKWALLPAPER which puts the path into a WCHAR and that is then inserted as the BackgroundImagePath.

I do not think an additional test would add value. The SPI_GETDESKTOPWALLPAPER uses the computers local wallpaper path and puts it into a WCHAR, which then I feed into BackgroundImagePath() as it's new path. I don't think there adds value in making a static path of the desktop background and testing that, given that static tests are already done for "BackgroundImage()".

Validation Steps Performed

(Manual Validation - Test False Value)

  1. Ran Terminal
  2. Set setting ["backgroundImage": ""] under profiles->defaults
  3. Verified terminal's background is not the desktops wallpaper.

(Manual Validation - Test True Value)

  1. Ran Terminal
  2. Set setting ["backgroundImage": "DesktopWallpaper"] under profiles->defaults
  3. Verified the background image matches the desktop background image.

(Manual Validation - Multiple Tabs True Value)

  1. Ran Terminal
  2. Set setting ["backgroundImage": "DesktopWallpaper"] under profiles->defaults
  3. Verified the background image matches the desktop background image.
  4. Opened new tabs
  5. Verified the background image matches the desktop background image for each tab.

@ghost ghost added Area-Settings Issues related to settings and customizability, for console or terminal Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. labels Oct 7, 2020
@github-actions

This comment has been minimized.

@cinnamon-msft
Copy link
Contributor

I'm wondering if this would be better suited as a parameter for the "backgroundImage" setting we already have. Such as:

"backgroundImage": "DesktopWallpaper"

@bennettnicholas
Copy link
Contributor Author

bennettnicholas commented Oct 7, 2020

@cinnamon-msft I initially tried to implement that, but after talking with Christ-Jan I thought it might be easier on the user to have a setting dedicated for this. A true/false value seems harder to mess up. I could add to the documentation to clarify that if true, it will ignore the "backgroundImage" setting.

Looking into the future with the settings GUI, it would be easier to convert the dedicated setting into the GUI. We could have it as a checkbox which would then remove the option to fill out any other background options if checked. Or some idea along those lines.

With that being said, your suggestion would be less code, which would be easier to maintain. I am open to reworking the issue if the team thinks having a keyword would be more valuable than a dedicated setting.

@carlos-zamora
Copy link
Member

@cinnamon-msft I initially tried to implement that, but after talking with Christ-Jan I thought it might be easier on the user to have a setting dedicated for this. A true/false value seems harder to mess up. I could add to the documentation to clarify that if true, it will ignore the "backgroundImage" setting.

I disagree with that, actually. Having multiple settings control which background image to use adds more confusion. It makes more sense to just have "backgroundImage" be the direct way to set your background image and go with @cinnamon-msft's plan above. Also, the attached issue says to do that.

Looking into the future with the settings GUI, it would be easier to convert the dedicated setting into the GUI. We could have it as a checkbox which would then remove the option to fill out any other background options if checked.

That's true, but the Settings UI doesn't have to align 1-to-1 with the json. We can still have your proposed GUI implementation, and just edit the JSON accordingly (which is probably what we'll do).

With that being said, your suggestion would be less code, which would be easier to maintain. I am open to reworking the issue if the team thinks having a keyword would be more valuable than a dedicated setting.

Kayla has a good handle on these user-facing issues so I agree with her. I recommend you keep an eye on CascadiaSettings::_ValidateMediaResources() though. You'll probably have to do a check there for this.

@bennettnicholas
Copy link
Contributor Author

bennettnicholas commented Oct 7, 2020

@carlos-zamora thanks for the feedback. I have made the changes. I am a bit sad how much easier @cinnamon-msft's implementation was. Would you rather have me update this PR or close and reopen with the new code?

@carlos-zamora
Copy link
Member

@carlos-zamora thanks for the feedback. I should have the changes implemented fairly quick. Would you rather have me update this PR or close and reopen with the new code?

100% update this PR haha. That way we can track the whole thing more easily. Feel free to reach out to @cinnamon-msft or I if you need any help with anything :). And thanks for the contribution! (should've started with that haha)

@bennettnicholas
Copy link
Contributor Author

bennettnicholas commented Oct 7, 2020

@carlos-zamora and @cinnamon-msft both the code and documentation has been updated. Please review both when you have the time. 😄 Documentation: MicrosoftDocs/terminal#155

@github-actions

This comment has been minimized.

Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure that this is the proper design. You're overwriting the BackgroundImagePath during a validation phase. I think at any time, the BackgroundImagePath shouldn't be changed, actually. Instead, it should be interpreted differently. See my thoughts on how expanding the path works below.

How Expanding the Background Image Path Works 1. We read the JSON (Profile.cpp) 2. We directly copy the text to the Profile object 3. When a TermControl is created, we specifically request the `ExpandedBackgroundImagePath` and resolve the file path then. 4. TermControl now has the full path and retrieves the background image

Step 3 is the important one. We don't modify Profile.

Consider the Settings UI. We want to present the value the user gave us, not the one that it resolves to. We specifically only want to resolve the value when it's needed.

So here's my suggestions:

  • "DesktopWallpaper" should be a static string off of Profile
  • Move this logic to ExpandedBackgroundImagePath (that way it's expanded when it's consumed)
  • Update _ValidateMediaResources saying that a value of DesktopWallpaper (reference the static string in bullet 1) is acceptable
  • Add a quick test showing that if you set the background image to "DesktopWallpaper" in the json, it gets exposed as "DesktopWallpaper" in profile.BackgroundImage() but something else in profile.ExpandedBackgroundImage.

src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp Outdated Show resolved Hide resolved
@ghost ghost added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Oct 7, 2020
… normal path. In addition, added a deserialization test
@github-actions
Copy link

github-actions bot commented Oct 8, 2020

New misspellings found, please review:

  • GETDESKWALLPAPER
  • UPDATEINIFILE
To accept these changes, run the following commands
perl -e '
my @expect_files=qw('".github/actions/spell-check/expect/alphabet.txt
.github/actions/spell-check/expect/expect.txt
.github/actions/spell-check/expect/web.txt"');
@ARGV=@expect_files;
my @stale=qw('"akb appdata Autogenerated debian debugbreak decf DECLL DECSMBV esa guidgenerator Inplace keith keybound notypeopt openlogo restrictederrorinfo richturn Scs Switchto winver Wlk wslhome "');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
  if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
  next if /^($re)(?:$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spell-check/expect/2193bf5de6391931605248cd6092e39f0b988d00.txt";
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"autogenerated Debian GETDESKWALLPAPER inplace UPDATEINIFILE WINVER "');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a) cmp lc($b)} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;'
git add .github/actions/spell-check/expect || echo '... you want to ensure .github/actions/spell-check/expect/2193bf5de6391931605248cd6092e39f0b988d00.txt is added to your repository...'
✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

⚠️ The command is written for posix shells. You can copy the contents of each perl command excluding the outer ' marks and dropping any '"/"' quotation mark pairs into a file and then run perl file.pl from the root of the repository to run the code. Alternatively, you can manually insert the items...

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spell-check/dictionary/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spell-check/dictionary/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spell-check/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spell-check/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The :check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

⚠️ Reviewers

At present, the action that triggered this message will not show its ❌ in this PR unless the branch is within this repository.
Thus, you should make sure that this comment has been addressed before encouraging the merge bot to merge this PR.

Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't have to update _ValidateMediaResources? I expected that when you set the background image to DesktopWallpaper, Terminal would give you a popup warning that it's not valid.

And don't worry about "slowing down", happy to help anyway I can. And hey, the more you learn, the more you can jump into the code! :) Thanks for the help!

src/cascadia/TerminalSettingsModel/Profile.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettingsModel/Profile.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettingsModel/Profile.cpp Outdated Show resolved Hide resolved
@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Oct 8, 2020
@bennettnicholas
Copy link
Contributor Author

@carlos-zamora I believe I have the spell check figured out, but waiting to confirm that. All of your comments should be resolved now

Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove that. That's probably why the CI build failed? I'd double check by build/deploy-ing Terminal after you remove that.

After that change is in, I'll approve :)

src/cascadia/TerminalSettingsModel/Profile.cpp Outdated Show resolved Hide resolved
@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Oct 9, 2020
@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Oct 9, 2020
Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I forgot to mention how to format your code! Run this with PowerShell and it should do it all for you:

Import-Module .\tools\OpenConsole.psm1
Invoke-CodeFormat

Approving since that's a quick and easy fix. CI seems to be failing for some unrelated reason aside from that.

As for other issues you can work on, take a look at our Easy-Starter issues here. You're more than welcome to tackle some other issues on our repo too. If you start one though, I suggest you post on the issue saying that you're gonna try and do it (and if you have any related questions). That way the team has an idea of what's going on 😊 Thanks!

@bennettnicholas
Copy link
Contributor Author

@carlos-zamora Thanks for all the help. @cinnamon-msft would you mind being a second reviewer? I pushed the formatted code.

@cinnamon-msft
Copy link
Contributor

I'd prefer if someone else from @microsoft/windows-console-team reviewed this since they are more familiar with the codebase.

@bennettnicholas
Copy link
Contributor Author

I'd prefer if someone else from @microsoft/windows-console-team reviewed this since they are more familiar with the codebase.

@cinnamon-msft works for me. I don't know any other devs, so you might have to tag one 😅

@zadjii-msft zadjii-msft self-assigned this Oct 12, 2020
@ghost ghost added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Oct 13, 2020
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If @cinnamon-msft is cool with this value being DesktopWallpaper, then I'm fine with this

@zadjii-msft zadjii-msft removed their assignment Oct 15, 2020
@zadjii-msft
Copy link
Member

Don't worry about the CI failure - that's resolved over in #7930

@bennettnicholas
Copy link
Contributor Author

bennettnicholas commented Oct 15, 2020

@zadjii-msft @cinnamon-msft @carlos-zamora @PankajBhojwani
Sounds good. I do not have the ability to merge. So merge it when the team would like to. Appreciate all the help. I learned way more than expected from such a simple ticket. Ill be on the hunt for another issue.

@zadjii-msft zadjii-msft added the AutoMerge Marked for automatic merge by the bot when requirements are met label Oct 15, 2020
@ghost
Copy link

ghost commented Oct 15, 2020

Hello @zadjii-msft!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 6e8388e into microsoft:master Oct 15, 2020
@ghost
Copy link

ghost commented Nov 11, 2020

🎉Windows Terminal Preview v1.5.3142.0 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Settings Issues related to settings and customizability, for console or terminal AutoMerge Marked for automatic merge by the bot when requirements are met hacktoberfest-accepted Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

option to autodetect desktop wallpaper for use as backgroundImage
7 participants